import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        BinarryTree binarryTree = new BinarryTree();
        BinarryTree.TreeNode root = binarryTree.createTree();
        BinarryTree.TreeNode p = root.left.right;
        BinarryTree.TreeNode q = root.left.left.left;
       // System.out.println(binarryTree.isCompleteTree(root));
        System.out.println(binarryTree.lowestCommonAncestor(root, p, q).ch);
    }
    public static void main3(String[] args) {

        BinarryTree binarryTree = new BinarryTree();
        BinarryTree.TreeNode root = binarryTree.createTree();
        System.out.println(binarryTree.levelOrder2(root));
    }
    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        BinarryTree binarryTree = new BinarryTree();
        binarryTree.inOrder(binarryTree.createTree(str));

    }
    public static void main1(String[] args) {
        BinarryTree binarryTree = new BinarryTree();
        BinarryTree.TreeNode root = binarryTree.createTree();
        binarryTree.preOrder(root);
        System.out.println();
        binarryTree.inOrder(root);
        System.out.println();
        binarryTree.postOrder(root);
        System.out.println();
       // System.out.println((binarryTree.size(root)));
        System.out.println("求根结点个数：");
        binarryTree.size2(root);
        System.out.println(BinarryTree.size);
        System.out.println("求叶子结点个数：");
        binarryTree.getLeafNodeCount(root);
       // System.out.println(binarryTree.count);
        System.out.println(binarryTree.getLeafNodeCount2(root));
        System.out.println("求root的第k层有多少个结点");
        System.out.println(binarryTree.getKLevelNodeCount(root,3));
        System.out.println("获取树的高度：");
        System.out.println(binarryTree.getHeight(root));
        System.out.println("检测值为value的元素是否存在");
      //  System.out.println(binarryTree.find(root,'A').ch);
       //binarryTree.isBalanced(root);
        System.out.println(binarryTree.isSymmetric(root));

    }
}
